package com.example.qwen03.controller;

import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.exception.NoApiKeyException;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*")
public class WanXiangContorller {

    @PostMapping("/upload")
    public Map<String, Object> uploadPhoto(MultipartFile photo) throws IOException {
        photo.transferTo(new File("E:\\lindada\\文件夹\\大三下\\东软实训\\AI\\photos\\" + photo.getOriginalFilename()));
        Map<String, Object> map = new HashMap<>();
        map.put("url","/ai/photos/"+photo.getOriginalFilename());
        return map;
    }


    @RequestMapping("/txting")
    public Map<String, Object> txting(String txt,int qty) throws NoApiKeyException {
        ImageSynthesis is = new ImageSynthesis();
        ImageSynthesisParam param =
                ImageSynthesisParam.builder()
                        .model(ImageSynthesis.Models.WANX_V1)
                        .n(qty)
                        .size("1024*1024")
                        .prompt("txt")
                        .build();

        ImageSynthesisResult result = is.call(param);
        System.out.println(result);
        Map<String, Object> map = new HashMap<>();
        map.put("txt",txt);
        map.put("qty",qty);
        map.put("result",result.getOutput().getResults());
        return map;


    }

}
